<?php

namespace App\Console\Commands;

use App\Services\DispatchService;
use App\Services\MonitorService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class AutoDispatchTransportCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dispatch:transport';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '将订单分配给承运商。';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        try {
            Log::notice('自动分配订单到承运【开始】');
            DispatchService::dispatchTransport();
            Log::notice('自动分配订单到承运【结束】');
        }catch (\Exception $e){
            MonitorService::addDispatchTransportException($e->getMessage());
            $this->error('自动分配订单到承运出错：'.$e->getMessage());
        }

    }
}
